<template>
  <div class="">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>商品分类</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域 -->
    <el-card>
      <el-row :gutter="20">
        <el-col :span=8>
          <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="getCateList">
            <el-button slot="append" icon="el-icon-search" @click="getCateList"></el-button>
          </el-input>
        </el-col>
        <el-col :span=4>
          <el-button type="primary" @click="goAddPage">
            添加商品
          </el-button>
        </el-col>
      </el-row>

      <!-- 表格 -->
      <el-row>
        <el-table :data="catelist" border stripe> 
          <el-table-column type="index"></el-table-column>
          <el-table-column prop="proName" label="商品名称"></el-table-column>
          <el-table-column  prop="proType" label="商品类型"></el-table-column>
          <el-table-column  prop="proDiscription" label="商品描述"></el-table-column>
          <el-table-column prop="prosize" label="商品尺寸"></el-table-column>
          <el-table-column  prop="proStates" label="商品状态" width="90px"></el-table-column>
          <el-table-column  prop="proPiece" label="商品件数" width="30px"></el-table-column>
          <el-table-column prop="proPrice" label="商品价格" width="90px"></el-table-column>
          <el-table-column  prop="createDate" label="创建时间" width="140px"></el-table-column>
          <el-table-column  prop="remarks" label="备注"></el-table-column>
          <el-table-column label="操作" width="130px">
            <template v-slot="scope">
              <el-button type="primary" icon="el-icon-edit" size="mini" @click="editProduct(1)"></el-button>
              <el-button type="danger" icon="el-icon-delete" size="mini" @click="removeById(scope.row.id)"></el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-row>
      <!-- 分页区域 -->
      <el-pagination  @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="queryInfo.pagenum"
        :page-sizes="[1, 2, 5, 10]" :page-size="queryInfo.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="total" background>
      </el-pagination>
    </el-card>



  </div>
</template>

<script>
 //import '../assets/js/cate.js'
  export default {
   data (){
     return {
       //查询条件
       queryInfo : {
         type : 3,
         pagenum : 1,
         pagesize : 5,
         query : ""
       },
       //数据列表
       catelist : [
         {
           "id" : 1,
           "proName" : "佛像",
           "proType" : "玉,人物",
           "proDiscription" : "由爱故生忧，由爱故生怖，若离于爱者，无忧亦无怖",
           "prosize" : "2cm长",
           "prosImg" : [],
           "createDate" : "2018-5-13",
           "remarks" : "11111",
           "proStates" : 0,  //0~有货 1~无货可接受预定 2~无货 暂不可接受预定
           "proPiece" :1,
           "proPrice" : 1000
         },
         {
           "id" : 2,
           "proName" : "马",
           "proType" : "玉,动物",
           "proDiscription" : "侯门有娇女，空欲窥颜色，譬彼琼树花，鲜艳自高立",
           "prosize" : "2cm长",
           "prosImg" : [],
           "createDate" : "2018-5-13",
           "remarks" : "11111",
           "proStates" : 1,  //0~有货 1~无货可接受预定 2~无货 暂不可接受预定
           "proPiece" : 0,
           "proPrice" : 1000
         }
       ],
       //总数据
       total : 2,
       
     }
   },
   created(){
     this.getCateList();
   },
   methods : {
     //请求商品表格数据
    async getCateList(){
      // const {data : res} = await this.$http.get('aaa' , {params:this.queryInfo})
      // if(res.meta.status !== 200){
      //   return this.$msg.error("获取商品表格失败");
      //   //把数据列表赋值给catelist
      //   this.catelist = res.data.result
      //   this.total = res.data.total
      // }
    },
    handleSizeChange(newSize){
      this.queryInfo.pagesize = newSize
      this.getCateList()
    },
    handleCurrentChange(newPage){
      this.queryInfo.pagenum = newPage
      this.getCateList()
    },
    async removeById(id){
      const confirmResult = await this.$confirm('此操作将永久删除该商品, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).catch(err => err)

      if(confirmResult !="confirm"){
        return this.$msg.info('已取消删除!')
      }
      //this.$http.delete("/delete")
      this.$msg.success("删除成功")
      this.getCateList()
    },
    goAddPage(){
      this.$router.push('/product/add')
    },
    editProduct(id){
      this.$router.push({path:'/product/edit',query:{"id":id}})
    }
   }
  }
</script>

<style lang="less" scoped>
  .el-breadcrumb{
     line-height: 30px;
  }
</style>
